<?php
	session_start();
	$userid=$_SESSION['account'];
	
	$app = [];
	$app['config'] = require 'config.php'; 
	require 'Core/DataBase/ConnetDB.php';
	$pdo = ConnetDB::make($app['config']['database']);
	
	$sql =  $pdo -> prepare("select isadmin from video where userName='$userid'");
	$sql->execute();
	
	$isadmins = $sql->fetchAll(PDO::FETCH_COLUMN, 0);
	if($isadmins[0][0]!="1")
	{
		echo '<script language="JavaScript">;alert("Sorry you no have permission to operate!");location.href="/";</script>;';
		exit();
	}
	
	if(isset($_GET['ot'])){
		$OT = $_GET['ot'];
	}
	
	if(isset($_GET['op'])){
		$OP = $_GET['op'];
	}
	
	if(isset($_GET['ou'])){
		$OU = $_GET['ou'];
	}
	
	if(isset($_GET['ay'])){
		$AY = $_GET['ay'];
	}
	
	if($OT == "unsetfenlei"){
		$statement = $pdo ->prepare("select fenlei from panel where id=1");
		$statement -> execute();
		$refenlei = $statement -> fetchAll();
		$arrayfenlei = explode("/*/*/",$refenlei[0][0]);//分割数据
		$temp = $arrayfenlei[$OP];
		unset($arrayfenlei[$OP]);
		$arrayfenlei = array_values($arrayfenlei);
		$totalfenlei = count($arrayfenlei);//计算数组的大小
		$ids = "";
		for($o=1;$o<=($totalfenlei-1);$o++)
		{
			$ids = $ids."/*/*/".$arrayfenlei[$o];
		}
		$statement = $pdo->prepare("UPDATE panel SET fenlei='$ids' WHERE id=1");
		$statement -> execute();
	}
	
	if($OT == "setfenlei"){
		$statement = $pdo->prepare("select fenlei from panel where id=1");
		$statement -> execute();
		$refenlei = $statement -> fetchAll();
		$fenlei = $refenlei[0][0]."/*/*/".$OP;
		$statement = $pdo->prepare("UPDATE panel SET fenlei='$fenlei' WHERE id=1");
		$statement -> execute();
	}
	
	if($OT == "fenlei"){
		if($OU == "0"){
			$statement = $pdo->prepare("UPDATE videos SET fenlei='$AY' WHERE id='$OP'");
			$statement -> execute();
		}else{
			for($a=$OP;$a<=$OU;$a++){
				$statement = $pdo->prepare("UPDATE videos SET fenlei='$AY' WHERE id='$a'");
				$statement -> execute();			
			}
		}
	}
	
	if($OT== "delsql"){
		$statement = $pdo->prepare("select vid from videos where id='$OP'");
		$statement -> execute();
		$isvid = $statement -> fetchAll();
		$statement = $pdo->prepare("select name from videos where id='$OP'");
		$statement -> execute();
		$isname = $statement -> fetchAll();
		$operlocal = getcwd()."/video/"; //视频目录
		$oper = getcwd()."/rubbish/"; //要存放的目录
		$operimg = getcwd()."/videoimg/"; //视频目录
		rename($operlocal.$isvid[0][0].".mp4", $oper.$isname[0][0].".mp4");
		rename($operimg.$isvid[0][0].".png", $oper.$isname[0][0].".png");
		$statement = $pdo->prepare("UPDATE videos SET isdel='1', fenlei='', watch='0' WHERE id='$OP'");
		$statement -> execute();
	}
	
	if($OT=="addadmin"){
		$statement = $pdo->prepare("UPDATE video SET isadmin='1' WHERE id='$OP'");
		$statement -> execute();
	}
	
	if($OT=="deladmin"){
		$statement = $pdo->prepare("UPDATE video SET isadmin='0' WHERE id='$OP'");
		$statement -> execute();
	}
	
	if($OT=="addupload"){
		$statement = $pdo->prepare("UPDATE video SET isupload='1' WHERE id='$OP'");
		$statement -> execute();
	}
	
	if($OT=="delupload"){
		$statement = $pdo->prepare("UPDATE video SET isupload='0' WHERE id='$OP'");
		$statement -> execute();
	}
	
	if($OT=="deluser"){
		$statement = $pdo->prepare("UPDATE video SET isdel='1' WHERE id='$OP'");
		$statement -> execute();
		$statement = $pdo->prepare("UPDATE loves SET loves='' WHERE id='$OP'");
		$statement -> execute();
	}
	
	

?>